package inglar.autotc.client.ui;


import com.google.gwt.user.client.ui.Composite;

/**
 * Creates {@link Composite} objects that can be displayed at the tree view of {@link PageDevices}
 * @author Lee
 * @sine 2011 JAN 05
 */
public class NodeFactory {
	
	private NodeFactory() {
		// DO NOT INSTANTIATE THIS WAY!
	}
	
	public static Composite getNode(String tcCmd, String device, PageDevices ref) {
		tcCmd = tcCmd.trim();
		
		// special case: a pfifo_fast at the root ONLY
		if(tcCmd.isEmpty()) { 
			return NodeQDisc.getDefaultRoot(device, ref);
		}
		
		String temp = tcCmd.substring(3).trim();
		String type = temp.substring(0, temp.indexOf(' ')).trim();
		
		if(type.equals("qdisc")) return new NodeQDisc(tcCmd, ref); 
		else if(type.equals("class")) return new NodeClass(tcCmd, ref);
		else if(type.equals("filter")) return new NodeFilter(tcCmd);
		else {
			return null;
		}
	}
}
